package com.clms.rents.service.impl;

import com.alibaba.nacos.common.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.clms.common.R;
import com.clms.rents.mapper.TabCommentMapper;
import com.clms.rents.pojo.entity.TbCar;
import com.clms.rents.pojo.entity.TbCarComment;
import com.clms.rents.pojo.entity.TbClient;
import com.clms.rents.pojo.vo.CarCommentVo;
import com.clms.rents.service.CarCommentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @program: clms-third
 * @description:
 * @author: 杨浩
 * @create: 2021-07-23 14:52
 **/
@Service
public class CarCommentServiceimpl implements CarCommentService {

    @Resource
    private TabCommentMapper tabCommentMapper;



    @Override
    public R selectall(Integer currentPage, Integer pageSize, CarCommentVo carCommentVo) {
        Page<TbCarComment> page=new Page<>(currentPage,pageSize);
        QueryWrapper<TbCar> queryWrapper=new QueryWrapper<>();
        if(StringUtils.isNotEmpty(carCommentVo.getCarName())){
            queryWrapper.like("carName",carCommentVo.getCarName());
        }
        IPage<TbCarComment> iPage=tabCommentMapper.selectall(page,queryWrapper);
        return R.ok().put("records",iPage.getRecords()).put("total",iPage.getTotal());
    }

    @Override
    public R insert(TbCarComment tbCarComment) {
        int i=tabCommentMapper.insert(tbCarComment);
        return R.ok();
    }

    @Override
    public R update(TbCarComment tbCarComment) {
        int i=tabCommentMapper.updateById(tbCarComment);
        return R.ok();
    }

    @Override
    public R selectById(Integer id) {
        TbCarComment tbCarComment = tabCommentMapper.selectById(id);
        return R.ok().put("huixian",tbCarComment);
    }

    @Override
    public R delete(Integer id) {
        int i=tabCommentMapper.deleteById(id);
        return R.ok();
    }
}
